package com.jghz.transfer.dao;

import java.util.Collection;
import java.util.Map;

import org.hibernate.annotations.common.util.StringHelper;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.bstek.dorado.data.provider.Page;
import com.jghz.framework.base.BaseDao;
import com.jghz.framework.utils.AppUtils;
import com.jghz.transfer.entity.Tbplateformcash;

@Repository
public class CashFlowDao extends BaseDao {

	public void pagingQuery(Page<Tbplateformcash> page, Map<String, Object> paramater) throws Exception {

		String senderCode = AppUtils.toString(paramater.get("senderCode"));
		String status = AppUtils.toString(paramater.get("status"));

		Object sendTimeF = paramater.get("sendTimeF");
		Object sendTimeT = paramater.get("sendTimeT");
		Object createDateF = paramater.get("createDateF");
		Object createDateT = paramater.get("createDateT");

		DetachedCriteria dc = DetachedCriteria.forClass(Tbplateformcash.class);

		if (!"admin".equals(senderCode)) {
			dc.add(Restrictions.eq("senderCode", senderCode));
		}
		if (StringHelper.isNotEmpty(status)) {
			dc.add(Restrictions.eq("status", status));
		}

		if (sendTimeF != null) {
			dc.add(Restrictions.ge("sendTime", sendTimeF));
		}
		if (sendTimeT != null) {
			dc.add(Restrictions.le("sendTime", sendTimeT));
		}
		if (createDateF != null) {
			dc.add(Restrictions.ge("create", createDateF));
		}
		if (createDateT != null) {
			dc.add(Restrictions.le("create", createDateT));
		}
		dc.addOrder(Order.desc("createDate"));
		getHibernateDao().pagingQuery(page, dc);

	}

	public Collection<?> queryCashByStatus(String status) {
		DetachedCriteria dc = DetachedCriteria.forClass(Tbplateformcash.class);
		dc.add(Restrictions.eq("status", status));
		return getHibernateDao().query(dc);
	}

	public int queryCountByStatus(String status) {
		DetachedCriteria dc = DetachedCriteria.forClass(Tbplateformcash.class);
		dc.add(Restrictions.eq("status", status));
		return getHibernateDao().queryCount(dc);
	}

	public void delete(Tbplateformcash Tbplateformcash) {
		getSession().delete(Tbplateformcash);
	}

	public void update(Tbplateformcash Tbplateformcash) {
		getSession().update(Tbplateformcash);
	}

	public void save(Tbplateformcash Tbplateformcash) {
		getSession().save(Tbplateformcash);
	}
}
